package com.shell.soda.car.controller;

import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 作者: creazier.huang
 * 日期: 2017/8/31
 * 说明:
 */
@ControllerAdvice(basePackages = "com.shell.soda.car.controller")
public class AppAdvice {
    @ExceptionHandler(Exception.class)
    public @ResponseBody  String exHandle(){
        return "error";
    }

    @InitBinder
    public void formatDate(WebDataBinder binder){
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        dateFormat.setLenient(false);
        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
    }

}
